import {
  Controller,
  Post,
  UseInterceptors,
  UploadedFile,
} from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { Public } from 'src/utils/public.decorator';
import { multerConfig } from 'src/config/multerConfig';

@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}

  @Public()
  @Post()
  @UseInterceptors(FileInterceptor('file', multerConfig)) //使用FileInterceptor处理上传的form data里的 file 字段的数据，也可以不指定字段名，直接处理整个表单数据
  async uploadFile(@UploadedFile() file: Express.Multer.File) {
    console.log(file);

    return await this.uploadService.create(file);
  }
}
